package com.cssl.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cssl.vo.Lv;
import com.cssl.vo.UserVo;

@RestController
@org.springframework.stereotype.Controller
public class Controller {
	
	@PostMapping("/demo")
	public String demo(UserVo uv) {
		System.out.println("demo demo .");
		System.out.println("name:"+uv.getUname());
		
		return "demo";
	}
	
	@PostMapping("/demo1")
	public String demo1(@RequestParam List<String> uname,Model md) {
		System.out.println("demo1 demo1 .");
		for (String s : uname) {
			System.out.println(s);
		}
		md.addAttribute("list",uname);
		return "demo";
	}
	
	@PostMapping("/demo2")
	public String demo2(@RequestParam Map<String,String> map,Model md) {
		System.out.println("demo2 demo2 .");
		map.forEach((k,v)->{
			System.out.println("k"+k+"v"+v);
		});
		md.addAttribute("map",map);
		return "demo";
	}
	
	@PostMapping("/demo3")
	public String demo3(String[] uname,Model md) {
		System.out.println("demo3 demo3 .");
		System.out.println(uname.length);
		for (String string : uname) {
			System.out.println(string);
		}
		md.addAttribute("uname",uname);
		return "demo";
	}
	
	//@ResponseBody
	@PostMapping("/demo4")
	public List<UserVo> demo4(UserVo uvo) {
		System.out.println("demo4 demo4 .");
		List<UserVo> list = new ArrayList<UserVo>();
		list.add(uvo);
		System.out.println(list);
		  
		for (UserVo userVo : list) {
			System.out.println(userVo.getId()+":::"+userVo.getUname()); 
		}
		 
		return list;
	}
	
	//@ResponseBody
	@PostMapping("/demo5")
	public List<UserVo> demo5(@RequestBody List<UserVo> list) {
		System.out.println("demo4 demo4 .");
		
		return list;
	}
}
